package com.guigu.connler;

import com.guigu.mapper.ManagementMapper;
import com.guigu.pojo.*;
import com.guigu.service.HvipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
public class HvipConnler {
@Autowired
    HvipService hvipService;
Integer vippid=null;
Integer updatevipid=null;
    //登录方法
    @RequestMapping("/user")
    public User selectuser(@RequestBody User user){
        User users = hvipService.selectuserKey(user);
        return users;
    }
    //账户注册
    @RequestMapping("/inuser")
    int insertSelece(@RequestBody User record){
        record.setUserimg("20230213114927.jpg");
        int i = hvipService.insertSelecti(record);
        return i;
    }
    //vip
    @RequestMapping("sele")
    //查询所有
   public List<Vip> selectVip(@RequestBody Vip vip){
        List<Vip> vips = hvipService.selectVip(vip);
        return vips;
    }
    @RequestMapping("del")
    //删除
   public int deletevip(@RequestBody Vip vip){
       int i = hvipService.deleteKey(vip);
       return i;
    }

    //分页
    @RequestMapping ("/info")
    public HPagevo<Vip> getinfovip(@RequestBody HPagevo hPagevo){
        HPagevo<Vip> infovip = hvipService.infovip(hPagevo);
        return infovip;
    }
    @RequestMapping ("/addvip")
    public int insertSele(@RequestBody MaxObject ob) {
        int i = hvipService.insertSele(ob.getVip());
        Integer vid = ob.getVip().getVid();
        vippid=vid;
        if(i==1&&ob.getCond()!=null){
            ob.getCond().setVid(vippid);
            int i1 = hvipService.insertSelectiv(ob.getCond());
            if(i1==1&&ob.getMed()!=null){
                ob.getMed().setVid(vippid);
                int insertm = hvipService.insertm(ob.getMed());

            }
        }
        return 1;
    }
    @RequestMapping ("/updatavip")//会员档案修改
    int updateByPrimaryKeySelective(@RequestBody MaxObject ob){
        ob.getVip().setVid(updatevipid);
        System.out.println("传过来的东西"+ob);
//        int i = hvipService.updateByPrimaryKeySelec(ob.getVip());
        System.out.println("什么东西"+updatevipid);
//        if(i==1&&ob.getCond()!=null){
//            ob.getCond().setVid(updatevipid);
//            int i1 = hvipService.updateByP(ob.getCond());
//            if (i1==1&&ob.getMed()!=null){
//                ob.getMed().setVid(updatevipid);
//                int i2 = hvipService.updateBy(ob.getMed());
//            }
//        }
        return 1;
    }

    @RequestMapping ("/addcon")
    int insertSelect(@RequestBody Conditionn record){
        record.setCondi(vippid);
        int i = hvipService.insertSelectiv(record);
        return i;
    }
    //修改vip的id查询
    @RequestMapping ("/ab")
    public MaxObject selvid( Integer vip){
        updatevipid=vip;
        Vip selvid = hvipService.selvid(vip);
        System.out.println("会员信息"+selvid);
        System.out.println(selvid.getVid());
        Conditionn seleconid = hvipService.seleconid(vip);
        System.out.println("体检信息"+seleconid);
        Medical selmeid = hvipService.selmeid(vip);
        System.out.println("病史"+selmeid);
        MaxObject maxObject = new MaxObject();
        maxObject.setVip(selvid);
        maxObject.setCond(seleconid);
        maxObject.setMed(selmeid);
        return maxObject;
    }



    //用户管理
    @RequestMapping("/manuse")
    public List<Management> manus(@RequestBody Management management){
        List<Management> manuse = hvipService.manuse(management);
        return manuse;
    }
    @RequestMapping ("/pageman")
    public HPagevo<Management> getinfoman(@RequestBody HPagevo hPagevo){
        HPagevo<Management> infovi = hvipService.infovi(hPagevo);
        return infovi;
    }
    @RequestMapping ("/add")
    int insertmana(@RequestBody Management record){
        int insertman = hvipService.insertman(record);
        return insertman;
    }
    @RequestMapping ("/delman")
    int deleteman( Integer id){
        int i = hvipService.deleteByyKey(id);
        return i;
    }
    @RequestMapping ("/upda")
    int updateByPrimaryKey(@RequestBody Management record){
        int i = hvipService.updateByPrimaryKey(record);
        return i;
    }
    @RequestMapping ("/selid")
    public Management seleid(Integer id){
        Management seid = hvipService.seid(id);
        return seid;
    }

    @RequestMapping("/bb")
    public List<Management> cx(){
        List<Management> selectjiankangguanlishi = hvipService.selectjiankangguanlishi();
        return selectjiankangguanlishi;
    }
    @RequestMapping ("/aa")
    public int insertm(@RequestBody Medical record){
        record.setId(vippid);
        int insertm = hvipService.insertm(record);
        return insertm;
    }
}


